/**
 *
 * 手机号脱敏
 *  15555556666 => 155****6666
 */

import { validMobileLoose } from "../valid/validMobile";

const hideMobile = (mobile) => {
  let tmp = "";
  if (!mobile) {
    return "";
  }
  if (validMobileLoose(mobile)) {
    if (typeof mobile === "number") {
      tmp = `${mobile}`;
    } else {
      tmp = mobile;
    }
    return tmp.replace(/^(\d{3})(\d{4})(\d{4})$/, "$1****$2");
  } else {
    console.error("输入的手机号码格式有误！");
    return "";
  }
};

export default hideMobile;
